﻿@model SMECustomerWebsite.Models.ViewModels.ProductHandbook.ProductHandbookChecklistViewModel
<ul id="menu_product_handbook_detail" class="nav nav-tabs bar_tabs sme-tabs" role="tablist">
    <li role="presentation" class="">
        @Html.ActionLink(@SMECustomerWebsite.Core.Resources.Resource.ProHandbookProDetailInfoTab, "ProductDetail", "ProductHandbook", new { productid = Request.QueryString["productid"] }, null)
    </li>
    <li role="presentation" class="active">
        @Html.ActionLink(@SMECustomerWebsite.Core.Resources.Resource.ProHandbookProDetailChecklistTab, "Checklist", "ProductHandbook", new { productid = Request.QueryString["productid"] }, null)
    </li>
</ul>
<div class="row">
    <div class="col-md-12">
        <div class="x_panel">
            <div class="x_title">
                <h2>CHECKLIST CUSTOMER</h2>
                <ul class="nav navbar-right panel_toolbox">
                    <li>
                        <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                    </li>
                </ul>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="row">
                        <div class="x_panel">
                            <div class="x_title">
                                <h2>@SMECustomerWebsite.Core.Resources.Resource.ChecklistCustInfoTitle</h2>
                                <ul class="nav navbar-right panel_toolbox">
                                    <li>
                                        <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                    </li>
                                </ul>
                                <div class="clearfix"></div>
                            </div>
                            <div class="x_content">
                                @switch (Model.CurrentUser.GroupIdentifier)
                                {
                                    case "1":
                                        <table id="checklist_customer" class="custom_table table table-bordered table-striped jambo_table">
                                            <thead class="headings">
                                                <tr>
                                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper()</th>
                                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                                    <th class="column-title">DAO</th>
                                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ChecklistLegalIdHeader</th>
                                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ChecklistCustAddDateHeader</th>
                                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ChecklistCustUpdateDateHeader</th>
                                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                                                </tr>
                                            </thead>
                                            <tbody></tbody>
                                        </table>
                                        break;
                                    case "2":
                                    <table id="checklist_customer" class="custom_table table table-bordered table-striped jambo_table">
                                        <thead class="headings">
                                            <tr>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                                <th class="column-title">DAO</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ChecklistLegalIdHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ChecklistCustAddDateHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ChecklistCustUpdateDateHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                                            </tr>
                                        </thead>
                                        <tbody></tbody>
                                    </table>
                                        break;
                                    case "3":
                                    <table id="checklist_customer" class="custom_table table table-bordered table-striped jambo_table">
                                        <thead class="headings">
                                            <tr>
                                                <th class="column-title">DAO</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ChecklistLegalIdHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ChecklistCustAddDateHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ChecklistCustUpdateDateHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                                            </tr>
                                        </thead>
                                        <tbody></tbody>
                                    </table>
                                        break;
                                    case "4":
                                    <table id="checklist_customer" class="custom_table table table-bordered table-striped jambo_table">
                                        <thead class="headings">
                                            <tr>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ChecklistLegalIdHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ChecklistCustAddDateHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ChecklistCustUpdateDateHeader</th>
                                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                                            </tr>
                                        </thead>
                                        <tbody></tbody>
                                    </table>
                                        break;
                                    default:
                                        break;
                                }
                                @*@if (Model.CurrentUser.GroupIdentifier.Equals("4"))
                                    {*@
                                <div class="ln_solid"></div>
                                <div class="form-group">
                                    <div class="col-md-12 col-sm-12 col-xs-12 col-md-offset-6">
                                        <a href="/ProductHandbook/CustChecklist?productid=@Request.QueryString["productid"]" class="btn btn-primary" id="pm-ap-cancel-btn">Add new</a>
                                        @*<button type="submit" class="btn btn-success">Add new</button>*@
                                    </div>
                                </div>
                                @*}*@

                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <!-- End to do list -->
</div>
@section scripts
{

    <script src="~/Scripts/tableeditable/dataTables.rowsGroup.js"></script>
    <!-- Add fancyBox main JS and CSS files -->
    <script type="text/javascript" src="~/Scripts/vendors/fancyImage/jquery.fancybox.js"></script>
    <link rel="stylesheet" type="text/css" href="~/Scripts/vendors/fancyImage/jquery.fancybox.css" media="screen" />
    <!-- Switchery -->
    <script src="~/Scripts/vendors/switchery/dist/switchery.min.js"></script>
    <!-- iCheck -->
    <script src="~/Scripts/vendors/iCheck/icheck.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {

            var totalColumn = [
                            { "sName": "CIF", "bSortable": false },
                            { "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "BUSINESS STATUS", "bSortable": false },
                            { "sName": "INFO", "bSortable": false }]
            var totalLenCol = 5;
            var totalCifCol = 0;
            var dataSearchTotalMatdt = [{ id: 0, text: 'CIF' }, { id: 1, text: 'Name' }, { id: 2, text: 'VPB Insdustry' },{ id: 3, text: 'Customer Status' }];
            switch (@Model.CurrentUser.GroupIdentifier)
            {
                case 1:
                    totalColumn = [
                           { "sName": "REGION", "bSortable": false },
                           { "sName": "BRANCH", "bSortable": false },
                           { "sName": "DAO", "bSortable": false },
                           { "sName": "MSBO", "bSortable": false },
                           { "sName": "CIF", "bSortable": false },
                            { "sName": "CIF", "bSortable": false },
                           { "sName": "NAME", "bSortable": false },
                           { "sName": "CUSTOMER STATUS", "bSortable": false },
                           { "sName": "BUSINESS STATUS", "bSortable": false },
                           { "sName": "INFO", "bSortable": false }];
                    totalLenCol = 9;
                    totalCifCol = 2;
                    dataSearchTotalMatdt = [{ id: 6, text: 'Region' }, { id: 4, text: 'Branch' }, { id: 5, text: 'MSBO' }, { id: 0, text: 'CIF' }, { id: 1, text: 'Name' }, { id: 2, text: 'VPB Insdustry' },{ id: 3, text: 'Customer Status' }];
                    break;
                case 2:
                    totalColumn=  [
                        { "sName": "BRANCH", "bSortable": false },
                        { "sName": "DAO", "bSortable": false },
                        { "sName": "MSBO", "bSortable": false },
                        { "sName": "CIF", "bSortable": false },
                            { "sName": "CIF", "bSortable": false },
                        { "sName": "NAME", "bSortable": false },
                        { "sName": "CUSTOMER STATUS", "bSortable": false },
                        { "sName": "BUSINESS STATUS", "bSortable": false },
                        { "sName": "INFO", "bSortable": false }];
                    totalLenCol = 8;
                    totalCifCol = 1;
                    dataSearchTotalMatdt = [{ id: 4, text: 'Branch' }, { id: 5, text: 'MSBO' }, { id: 0, text: 'CIF' }, { id: 1, text: 'Name' }, { id: 2, text: 'VPB Insdustry' },{ id: 3, text: 'Customer Status' }];
                    break;
                case 3:
                    totalColumn= [
                        { "sName": "DAO", "bSortable": false },
                        { "sName": "MSBO", "bSortable": false },
                        { "sName": "CIF", "bSortable": false },
                            { "sName": "CIF", "bSortable": false },
                        { "sName": "NAME", "bSortable": false },
                        { "sName": "CUSTOMER STATUS", "bSortable": false },
                        { "sName": "BUSINESS STATUS", "bSortable": false },
                        { "sName": "INFO", "bSortable": false }];
                    totalLenCol = 7;
                    totalCifCol = 0;
                    dataSearchTotalMatdt = [{ id: 5, text: 'MSBO' }, { id: 0, text: 'CIF' }, { id: 1, text: 'Name' }, { id: 2, text: 'VPB Insdustry' },{ id: 3, text: 'Customer Status' }];
                    break;
                default:
                    break;
            }
            var table_cust = $('#checklist_customer').DataTable({
                "paging": true,
                "order": [[0, 'asc']],
                "bServerSide": true,
                "bProcessing": true,
                "responsive": true,
                "bAutoWidth": false,
                "aLengthMenu": [10, 30, 50, 100],
                "pageLength": 10,
                rowsGroup: [0, 1, 2,3],
                "sAjaxSource": '@Url.Action("ListCustomerChecklistData", "ProductHandbook", new { productid = Request.QueryString["productid"] })',
                "fnServerData": function (sSource, aoData, fnCallback) {
                    $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": fnCallback
                    });
                },
                'fnCreatedRow': function (nRow, aData, iDataIndex) {
                    $(nRow).attr('id', 'my_account_planning' + iDataIndex); // or whatever you choose to set as the id
                    $('td', nRow).eq(4).attr('id', 'td_' + iDataIndex + '_action');
                },
                "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'dataTables_wrapper'ip>>",
                "sPaginationType": "simple_numbers",//"full_numbers",
                "aoColumns":totalColumn,
                "aoColumnDefs": [{
                    "sClass": "column-title",
                    "aTargets": [totalLenCol],
                    "mRender": function (data, type, full) {
                        if ('@Model.CurrentUser.Dao' == full[totalCifCol] || @Model.CurrentUser.GroupIdentifier == 4) {
                            return '<a class=\"btn btn-primary btn-xs\" href="/ProductHandbook/ViewChecklist?ccid='+full[totalLenCol]+'"><i class="fa fa-eye"></i></a><a class=\"btn btn-primary btn-xs\" href="/ProductHandbook/EditChecklist?ccid='+full[totalLenCol]+'"><i class="fa fa-edit"></i></a>';
                        }else{
                            return '<a class=\"btn btn-primary btn-xs\" href="/ProductHandbook/ViewChecklist?ccid='+full[totalLenCol]+'"><i class="fa fa-eye"></i></a>';
                        }

                    }
                }],
                "drawCallback": function (settings) {
                    $('table.custom_table th').removeClass().addClass('column-title');
                }
            });

            //show document image
            function showDocumentPicture(picName) {
                var arrPic = picName.split(",");
                var arrFancy = [];
                arrPic.forEach(function (entry) {
                    arrFancy.push({
                        href: '/Scripts/vendors/fancyImage/@Request.QueryString["productid"]/' + entry
                    })
                });
                $.fancybox.open(arrFancy, {
                    helpers: {
                        thumbs: {
                            width: 75,
                            height: 50
                        }
                    }
                });
            };

            function showMore(id) {
                if ($("#more" + id + "").text() == "...(more)") {
                    $("#complete" + id + "").show();
                    $("#more" + id + "").text(" (less)");
                } else {
                    $("#complete" + id + "").hide();
                    $("#more" + id + "").text("...(more)");
                }
            }
        });
    </script>
}
